package com.study.day1;

import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;

/**
 * 模版
 */
class Solution59_2 {

    public static class MaxQueue {
        // 队列
        Queue<Integer> queue;
        // 双向队列
        Deque<Integer> deque;

        public MaxQueue() {
            queue = new LinkedList<>();
            deque = new LinkedList<>();
        }

        public int max_value() {
            return deque.isEmpty() ? -1 : deque.peekFirst();
        }

        public void push_back(int value) {
            queue.offer(value);
            while (!deque.isEmpty() && deque.peekLast() < value) {
                deque.removeLast();
            }
            deque.offerLast(value);
        }

        public int pop_front() {
            if (queue.isEmpty()) {
                return -1;
            }
            if (queue.peek().equals(deque.peekFirst())) {
                deque.pollFirst();
            }
            return queue.poll();

        }
    }





    public static void main(String[] args) {
        // ======= Test Case =======

        // Build next reference

    }
}

